package com.lanyun.interceptor;/**
 * @author zhy
 * @date 2021/1/14 - 10:44
 */

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**

 @ClassName URLInterceptor
 @Description xxx
 @Author zhy
 @Date 2021/1/14 - 10:44
 @Version 1.0
 **/
@Component
public class URLInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        if (session.getAttribute(LoginConfig.SESSION_KEY) != null){
            return true;
        }
        String url = "/login";
        session.setAttribute("loginError","小伙子，步子迈的太大了，正常走登录吧！！！");
        response.sendRedirect(url);
        return false;
    }
}
